
<!DOCTYPE HTML>
<html lang="zh-hans" >
<head>
    <meta charset="UTF-8">
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
    <title>11.7：Json转Dart Model类 · 《Flutter实战》</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="baidu-site-verification" content="Y34sAqDKUH"/>
    <meta name="theme-color" content="#ffffff">
    <!--<meta name="description" content="">-->
    <meta name="description" content="《Flutter实战》是Flutter中文网（https://flutterchina.club）开源的电子书，旨在帮助开发者系统化的了解并学习Flutter。">
    <meta name="keywords" content="flutter实战,flutter书籍,flutter电子书,flutter中文网 ">
    <meta name="generator" content="GitBook 3.2.3">
    
    <meta name="author" content="wendux 824783146@qq.com">
    
    
    
    
    <link rel="stylesheet" href="https://pcdn.flutterchina.club/gitbook/style.css">

    
    
    
    <link rel="stylesheet" href="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-search-pro/search.css">
    
    
    
    <link rel="stylesheet" href="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-ace/ace.css">
    
    
    
    <link rel="stylesheet" href="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-splitter/splitter.css">
    
    
    
    <link rel="stylesheet" href="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-prism/prism.css">
    
    
    
    <link rel="stylesheet" href="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-donate/plugin.css">
    
    
    
    <link rel="stylesheet" href="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-fontsettings/website.css">
    
    
    

    

    
        
    
        
    
        
    
        
    
        
    

    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="https://pcdn.flutterchina.club/gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="https://pcdn.flutterchina.club/gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="../chapter12/" />
    
    
    <link rel="prev" href="socket.html" />
    

    <style>
        .pull-right > i {
            font-size: 25px;
            color: #777 !important;
            cursor: pointer;

        }

        .pull-right > i:hover {
            color: #777 !important;
        }

        body {
            font-size: 15px !important;
        }

        a[href='../todo.html'], a[href='todo.html'] {
            color: #888 !important;
        }

        .copyright {
            text-align: center;
            margin: 80px 16px 8px 16px;
            padding-top: 16px;
            border-top: #eee 1px solid;
            color: grey;
            font-size: .9em;
        }

        .f-links a{
            text-decoration: underline;
            color: dodgerblue !important;
        }

        .f-links a:hover{
            opacity: .8 !important;
        }

        /*.ad {*/
            /*color: white;*/
            /*text-align: center;*/
            /*background: url(https://img.alicdn.com/tfs/TB1Huu7vMmTBuNjy1XbXXaMrVXa-2880-400.png);*/
            /*background-size: cover;*/
            /*cursor: pointer;*/
            /*margin-bottom: 30px;*/
            /*padding: 18px*/
        /*}*/

        /*.ad:hover {*/
            /*opacity: .8;*/
        /*}*/

        .buy-btn {
            text-decoration: none !important;
            padding: 8px 18px;
            border: #268bd2 1px solid !important;
            display: inline-block !important;
            border-radius: 25px;
            color: #268bd2;
            margin-top: 10px;
        }

        .buy-btn:hover {
            transition: all ease 200ms;
            box-shadow: #555 2px 5px 10px;
            background: #eee;
            color: dodgerblue !important;
        }

        .maoyun{
            padding-top: 5px;
        }


    </style>
</head>
<body>
<!--<div id="ad" style="display: none">-->
<!--<div class="ad ad0"-->
<!--onclick="_track('aliyun','https://promotion.aliyun.com/ntms/yunparter/invite.html?userCode=8hhi4dts')">-->
<!--<div style="font-size: 1.3em; padding-right: 120px; position: relative; top: 12px">阿里云新春特惠</div>-->
<!--<div style="color:orange; font-size: 13px">限时红包 最高￥<span style="font-size: 40px">1888</span></div>-->
<!--</div>-->
<!--<div class="ad ad1"-->
<!--onclick="_track('aliyun-puhui','https://promotion.aliyun.com/ntms/act/qwbk.html?spm=5176.11533457.1089570.10.74e877e33jtaGy&userCode=8hhi4dts')">-->
<!--<div style="font-size: 1.5em;">阿里云全民云计算-新春特惠</div>-->
<!--<div style="color:orange; font-size: 18px;padding-top: 4px;">普惠上云，云服务器1核1G仅需293元/年</div>-->
<!--</div>-->
<!--</div>-->

<div class="ad"  style="text-align:center; padding-bottom:30px; display: none"><a href="https://item.jd.com/12816296.html" onclick="buy('img')" title='点击购买' target="_blank"><img style="height:250px;box-shadow: #aaa 5px 5px 10px;" src="https://pcdn.flutterchina.club/imgs/book.png"/></a>  <br/> <a class="buy-btn" onclick="buy('btn')" href="https://item.jd.com/12816296.html" title='点击购买' target="_blank"> 购买实体书 </a></div>


<!--<div class="ad"  style="text-align:center; padding-bottom:30px; display: none"><a href="https://item.jd.com/12816296.html" onclick="buy('img')" title='点击购买' target="_blank"><img style="height:250px;box-shadow: #aaa 5px 5px 10px;" src="https://pcdn.flutterchina.club/imgs/book.png"/></a>  <br/> <a class="buy-btn" onclick="buy('img')" href="https://item.jd.com/12816296.html" title='点击购买' target="_blank"> 购买实体书 </a>-->
    <!--<a id="jd" href="https://item.jd.com/12816296.html" onclick="buy('jd')"  style=" display: block; padding: 10px; color: red; text-decoration: underline; ">即日起至4.23日，京东图书每满100减50！ </a>-->
<!--</div>-->


<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="https://flutterchina.club" target="_blank" class="custom-link"><div><img height=20 style='position:relative; top:5px; padding-right:5px ' src='https://cdn.jsdelivr.net/gh/flutterchina/website@1.0/images/favicon.png'/> Flutter中文网</div></a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../intro.html">
            
                <a href="../intro.html">
            
                    
                    前言
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">入门篇</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../chapter1/">
            
                <a href="../chapter1/">
            
                    
                    第一章：起步
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1.1" data-path="../chapter1/mobile_development_intro.html">
            
                <a href="../chapter1/mobile_development_intro.html">
            
                    
                    1.1：移动开发技术简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.2" data-path="../chapter1/flutter_intro.html">
            
                <a href="../chapter1/flutter_intro.html">
            
                    
                    1.2：初识Flutter
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.3" data-path="../chapter1/install_flutter.html">
            
                <a href="../chapter1/install_flutter.html">
            
                    
                    1.3：搭建Flutter开发环境
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.4" data-path="../chapter1/dart.html">
            
                <a href="../chapter1/dart.html">
            
                    
                    1.4：Dart语言简介
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="../chapter2/">
            
                <a href="../chapter2/">
            
                    
                    第二章：第一个Flutter应用
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.2.1" data-path="../chapter2/first_flutter_app.html">
            
                <a href="../chapter2/first_flutter_app.html">
            
                    
                    2.1：计数器示例
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2.2" data-path="../chapter2/flutter_router.html">
            
                <a href="../chapter2/flutter_router.html">
            
                    
                    2.2：路由管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2.3" data-path="../chapter2/flutter_package_mgr.html">
            
                <a href="../chapter2/flutter_package_mgr.html">
            
                    
                    2.3：包管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2.4" data-path="../chapter2/flutter_assets_mgr.html">
            
                <a href="../chapter2/flutter_assets_mgr.html">
            
                    
                    2.4：资源管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2.5" data-path="../chapter2/flutter_app_debug.html">
            
                <a href="../chapter2/flutter_app_debug.html">
            
                    
                    2.5：调试Flutter APP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2.6" data-path="../chapter2/thread_model_and_error_report.html">
            
                <a href="../chapter2/thread_model_and_error_report.html">
            
                    
                    2.6：Dart线程模型及异常捕获
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="../chapter3/">
            
                <a href="../chapter3/">
            
                    
                    第三章：基础组件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.3.1" data-path="../chapter3/flutter_widget_intro.html">
            
                <a href="../chapter3/flutter_widget_intro.html">
            
                    
                    3.1：Widget简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.2" data-path="../chapter3/state_manage.html">
            
                <a href="../chapter3/state_manage.html">
            
                    
                    3.2：状态管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.3" data-path="../chapter3/text.html">
            
                <a href="../chapter3/text.html">
            
                    
                    3.3：文本、字体样式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.4" data-path="../chapter3/buttons.html">
            
                <a href="../chapter3/buttons.html">
            
                    
                    3.4：按钮
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.5" data-path="../chapter3/img_and_icon.html">
            
                <a href="../chapter3/img_and_icon.html">
            
                    
                    3.5：图片和Icon
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.6" data-path="../chapter3/radio_and_checkbox.html">
            
                <a href="../chapter3/radio_and_checkbox.html">
            
                    
                    3.6：单选框和复选框
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.7" data-path="../chapter3/input_and_form.html">
            
                <a href="../chapter3/input_and_form.html">
            
                    
                    3.7：输入框和表单
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.8" data-path="../chapter3/progress.html">
            
                <a href="../chapter3/progress.html">
            
                    
                    3.8：进度指示器
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="../chapter4/">
            
                <a href="../chapter4/">
            
                    
                    第四章：布局类组件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.4.1" data-path="../chapter4/intro.html">
            
                <a href="../chapter4/intro.html">
            
                    
                    4.1：布局类组件简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.2" data-path="../chapter4/row_and_column.html">
            
                <a href="../chapter4/row_and_column.html">
            
                    
                    4.2：线性布局（Row、Column）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.3" data-path="../chapter4/flex.html">
            
                <a href="../chapter4/flex.html">
            
                    
                    4.3：弹性布局（Flex）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.4" data-path="../chapter4/wrap_and_flow.html">
            
                <a href="../chapter4/wrap_and_flow.html">
            
                    
                    4.4：流式布局（Wrap、Flow）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.5" data-path="../chapter4/stack.html">
            
                <a href="../chapter4/stack.html">
            
                    
                    4.5：层叠布局（Stack、Positioned）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.6" data-path="../chapter4/alignment.html">
            
                <a href="../chapter4/alignment.html">
            
                    
                    4.6：对齐与相对定位（Align）
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="../chapter5/">
            
                <a href="../chapter5/">
            
                    
                    第五章：容器类组件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.5.1" data-path="../chapter5/padding.html">
            
                <a href="../chapter5/padding.html">
            
                    
                    5.1：填充（Padding）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5.2" data-path="../chapter5/constrainedbox_and_sizebox.html">
            
                <a href="../chapter5/constrainedbox_and_sizebox.html">
            
                    
                    5.2：尺寸限制类容器（ConstrainedBox等）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5.3" data-path="../chapter5/decoratedbox.html">
            
                <a href="../chapter5/decoratedbox.html">
            
                    
                    5.3：装饰容器（DecoratedBox）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5.4" data-path="../chapter5/transform.html">
            
                <a href="../chapter5/transform.html">
            
                    
                    5.4：变换（Transform）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5.5" data-path="../chapter5/container.html">
            
                <a href="../chapter5/container.html">
            
                    
                    5.5：Container容器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5.6" data-path="../chapter5/material_scaffold.html">
            
                <a href="../chapter5/material_scaffold.html">
            
                    
                    5.6：Scaffold、TabBar、底部导航
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5.7" data-path="../chapter5/clip.html">
            
                <a href="../chapter5/clip.html">
            
                    
                    5.7：剪裁（Clip）
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="../chapter6/">
            
                <a href="../chapter6/">
            
                    
                    第六章：可滚动组件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.6.1" data-path="../chapter6/intro.html">
            
                <a href="../chapter6/intro.html">
            
                    
                    6.1：可滚动组件简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.2" data-path="../chapter6/single_child_scrollview.html">
            
                <a href="../chapter6/single_child_scrollview.html">
            
                    
                    6.2：SingleChildScrollView
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.3" data-path="../chapter6/listview.html">
            
                <a href="../chapter6/listview.html">
            
                    
                    6.3：ListView
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.4" data-path="../chapter6/gridview.html">
            
                <a href="../chapter6/gridview.html">
            
                    
                    6.4：GridView
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.5" data-path="../chapter6/custom_scrollview.html">
            
                <a href="../chapter6/custom_scrollview.html">
            
                    
                    6.5：CustomScrollView
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.6" data-path="../chapter6/scroll_controller.html">
            
                <a href="../chapter6/scroll_controller.html">
            
                    
                    6.6：滚动监听及控制（ScrollController）
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="../chapter7/">
            
                <a href="../chapter7/">
            
                    
                    第七章：功能型组件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.7.1" data-path="../chapter7/willpopscope.html">
            
                <a href="../chapter7/willpopscope.html">
            
                    
                    7.1：导航返回拦截（WillPopScope）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7.2" data-path="../chapter7/inherited_widget.html">
            
                <a href="../chapter7/inherited_widget.html">
            
                    
                    7.2：数据共享（InheritedWidget）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7.3" data-path="../chapter7/provider.html">
            
                <a href="../chapter7/provider.html">
            
                    
                    7.3： 跨组件状态共享（Provider）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7.4" data-path="../chapter7/theme.html">
            
                <a href="../chapter7/theme.html">
            
                    
                    7.4：颜色和主题（Theme）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7.5" data-path="../chapter7/futurebuilder_and_streambuilder.html">
            
                <a href="../chapter7/futurebuilder_and_streambuilder.html">
            
                    
                    7.5：异步UI更新（FutureBuilder、StreamBuilder）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7.6" data-path="../chapter7/dailog.html">
            
                <a href="../chapter7/dailog.html">
            
                    
                    7.6：对话框详解
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">进阶篇</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../chapter8/">
            
                <a href="../chapter8/">
            
                    
                    第八章：事件处理与通知
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1.1" data-path="../chapter8/listener.html">
            
                <a href="../chapter8/listener.html">
            
                    
                    8.1：原始指针事件处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.2" data-path="../chapter8/gesture.html">
            
                <a href="../chapter8/gesture.html">
            
                    
                    8.2：手势识别
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.3" data-path="../chapter8/eventbus.html">
            
                <a href="../chapter8/eventbus.html">
            
                    
                    8.3：全局事件总线
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.4" data-path="../chapter8/notification.html">
            
                <a href="../chapter8/notification.html">
            
                    
                    8.4：通知(Notification)
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="../chapter9/">
            
                <a href="../chapter9/">
            
                    
                    第九章：动画
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.2.1" data-path="../chapter9/intro.html">
            
                <a href="../chapter9/intro.html">
            
                    
                    9.1：Flutter动画简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.2" data-path="../chapter9/animation_structure.html">
            
                <a href="../chapter9/animation_structure.html">
            
                    
                    9.2：动画结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.3" data-path="../chapter9/route_transition.html">
            
                <a href="../chapter9/route_transition.html">
            
                    
                    9.3：自定义路由过渡动画
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.4" data-path="../chapter9/hero.html">
            
                <a href="../chapter9/hero.html">
            
                    
                    9.4：Hero动画
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.5" data-path="../chapter9/stagger_animation.html">
            
                <a href="../chapter9/stagger_animation.html">
            
                    
                    9.5：交织动画
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.6" data-path="../chapter9/animated_switcher.html">
            
                <a href="../chapter9/animated_switcher.html">
            
                    
                    9.6：通用“动画切换”组件（AnimatedSwitcher）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.7" data-path="../chapter9/animated_widgets.html">
            
                <a href="../chapter9/animated_widgets.html">
            
                    
                    9.7：动画过渡组件
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="../chapter10/">
            
                <a href="../chapter10/">
            
                    
                    第十章：自定义组件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.3.1" data-path="../chapter10/intro.html">
            
                <a href="../chapter10/intro.html">
            
                    
                    10.1：自定义组件方法简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3.2" data-path="../chapter10/combine.html">
            
                <a href="../chapter10/combine.html">
            
                    
                    10.2：组合现有组件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3.3" data-path="../chapter10/turn_box.html">
            
                <a href="../chapter10/turn_box.html">
            
                    
                    10.3：组合实例：TurnBox
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3.4" data-path="../chapter10/custom_paint.html">
            
                <a href="../chapter10/custom_paint.html">
            
                    
                    10.4：自绘组件（CustomPaint与Canvas）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3.5" data-path="../chapter10/gradient_circular_progress_demo.html">
            
                <a href="../chapter10/gradient_circular_progress_demo.html">
            
                    
                    10.5：自绘实例：圆形渐变进度条(自绘)
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="./">
            
                <a href="./">
            
                    
                    第十一章：文件操作与网络请求
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.4.1" data-path="file_operation.html">
            
                <a href="file_operation.html">
            
                    
                    11.1：文件操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.2" data-path="http.html">
            
                <a href="http.html">
            
                    
                    11.2：Http请求-HttpClient
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.3" data-path="dio.html">
            
                <a href="dio.html">
            
                    
                    11.3：Http请求-Dio package
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.4" data-path="download_with_chunks.html">
            
                <a href="download_with_chunks.html">
            
                    
                    11.4：实例：Http分块下载
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.5" data-path="websocket.html">
            
                <a href="websocket.html">
            
                    
                    11.5：WebSocket
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.6" data-path="socket.html">
            
                <a href="socket.html">
            
                    
                    11.6：使用Socket API
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="3.4.7" data-path="json_model.html">
            
                <a href="json_model.html">
            
                    
                    11.7：Json转Dart Model类
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="../chapter12/">
            
                <a href="../chapter12/">
            
                    
                    第十二章：包与插件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.5.1" data-path="../chapter12/develop_package.html">
            
                <a href="../chapter12/develop_package.html">
            
                    
                    12.1：开发package
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5.2" data-path="../chapter12/platform-channel.html">
            
                <a href="../chapter12/platform-channel.html">
            
                    
                    12.2：平台通道简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5.3" data-path="../chapter12/develop_plugin.html">
            
                <a href="../chapter12/develop_plugin.html">
            
                    
                    12.3：开发Flutter插件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5.4" data-path="../chapter12/android_implement.html">
            
                <a href="../chapter12/android_implement.html">
            
                    
                    12.4：插件开发：实现Android端API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5.5" data-path="../chapter12/ios_implement.html">
            
                <a href="../chapter12/ios_implement.html">
            
                    
                    12.5：插件开发：实现IOS端API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5.6" data-path="../chapter12/texture_platformview.html">
            
                <a href="../chapter12/texture_platformview.html">
            
                    
                    12.6：Texture和PlatformView
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="../chapter13/">
            
                <a href="../chapter13/">
            
                    
                    第十三章：国际化
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.6.1" data-path="../chapter13/multi_languages_support.html">
            
                <a href="../chapter13/multi_languages_support.html">
            
                    
                    13.1：让App支持多语言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.6.2" data-path="../chapter13/locallization_implement.html">
            
                <a href="../chapter13/locallization_implement.html">
            
                    
                    13.2：实现Localizations
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.6.3" data-path="../chapter13/intl.html">
            
                <a href="../chapter13/intl.html">
            
                    
                    13.3：使用Intl包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.6.4" data-path="../chapter13/faq.html">
            
                <a href="../chapter13/faq.html">
            
                    
                    13.4：国际化常见问题
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.7" data-path="../chapter14/">
            
                <a href="../chapter14/">
            
                    
                    第十四章：Flutter核心原理
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.7.1" data-path="../chapter14/flutter_ui_system.html">
            
                <a href="../chapter14/flutter_ui_system.html">
            
                    
                    14.1：Flutter UI系统
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7.2" data-path="../chapter14/element_buildcontext.html">
            
                <a href="../chapter14/element_buildcontext.html">
            
                    
                    14.2：Element和BuildContext
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7.3" data-path="../chapter14/render_object.html">
            
                <a href="../chapter14/render_object.html">
            
                    
                    14.3：RenderObject与RenderBox
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7.4" data-path="../chapter14/flutter_app_startup.html">
            
                <a href="../chapter14/flutter_app_startup.html">
            
                    
                    14.4：Flutter从启动到显示
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7.5" data-path="../chapter14/image_and_cache.html">
            
                <a href="../chapter14/image_and_cache.html">
            
                    
                    14.5：Flutter图片加载与缓存
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">实例篇</li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="../chapter15/intro.html">
            
                <a href="../chapter15/intro.html">
            
                    
                    第十五章：一个完整的Flutter应用
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1.1" data-path="../chapter15/intro.html">
            
                <a href="../chapter15/intro.html">
            
                    
                    15.1：应用简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.2" data-path="../chapter15/code_structure.html">
            
                <a href="../chapter15/code_structure.html">
            
                    
                    15.2：APP代码结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.3" data-path="../chapter15/models.html">
            
                <a href="../chapter15/models.html">
            
                    
                    15.3：Model类定义
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.4" data-path="../chapter15/globals.html">
            
                <a href="../chapter15/globals.html">
            
                    
                    15.4：全局变量及共享状态
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.5" data-path="../chapter15/network.html">
            
                <a href="../chapter15/network.html">
            
                    
                    15.5：网络请求封装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.6" data-path="../chapter15/entry.html">
            
                <a href="../chapter15/entry.html">
            
                    
                    15.6：App入口及首页
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.7" data-path="../chapter15/login_page.html">
            
                <a href="../chapter15/login_page.html">
            
                    
                    15.7：登录页
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.8" data-path="../chapter15/language_and_theme_setting.html">
            
                <a href="../chapter15/language_and_theme_setting.html">
            
                    
                    15.8：多语言和多主题
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="https://pcdn.flutterchina.club/gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    
    <a class="btn pull-right" aria-label="GitHub">
        <i class="fa fa-edit" title="编辑本文"></i>
    </a>
    <a class="btn pull-right" aria-label="GitHub" href="https://github.com/flutterchina/flutter-in-action">
        <i class="fa fa-github" title="查看本书开源项目"></i>
    </a>
    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >11.7：Json转Dart Model类</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="117-json&#x8F6C;dart-model&#x7C7B;">11.7 Json&#x8F6C;Dart Model&#x7C7B;</h1>
<p>&#x5728;&#x5B9E;&#x6218;&#x4E2D;&#xFF0C;&#x540E;&#x53F0;&#x63A5;&#x53E3;&#x5F80;&#x5F80;&#x4F1A;&#x8FD4;&#x56DE;&#x4E00;&#x4E9B;&#x7ED3;&#x6784;&#x5316;&#x6570;&#x636E;&#xFF0C;&#x5982;JSON&#x3001;XML&#x7B49;&#xFF0C;&#x5982;&#x4E4B;&#x524D;&#x6211;&#x4EEC;&#x8BF7;&#x6C42;Github API&#x7684;&#x793A;&#x4F8B;&#xFF0C;&#x5B83;&#x8FD4;&#x56DE;&#x7684;&#x6570;&#x636E;&#x5C31;&#x662F;JSON&#x683C;&#x5F0F;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x4E3A;&#x4E86;&#x65B9;&#x4FBF;&#x6211;&#x4EEC;&#x5728;&#x4EE3;&#x7801;&#x4E2D;&#x64CD;&#x4F5C;JSON&#xFF0C;&#x6211;&#x4EEC;&#x5148;&#x5C06;JSON&#x683C;&#x5F0F;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x8F6C;&#x4E3A;Dart&#x5BF9;&#x8C61;&#xFF0C;&#x8FD9;&#x4E2A;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;<code>dart:convert</code>&#x4E2D;&#x5185;&#x7F6E;&#x7684;JSON&#x89E3;&#x7801;&#x5668;json.decode() &#x6765;&#x5B9E;&#x73B0;&#xFF0C;&#x8BE5;&#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x6839;&#x636E;JSON&#x5B57;&#x7B26;&#x4E32;&#x5177;&#x4F53;&#x5185;&#x5BB9;&#x5C06;&#x5176;&#x8F6C;&#x4E3A;List&#x6216;Map&#xFF0C;&#x8FD9;&#x6837;&#x6211;&#x4EEC;&#x5C31;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x4ED6;&#x4EEC;&#x6765;&#x67E5;&#x627E;&#x6240;&#x9700;&#x7684;&#x503C;&#xFF0C;&#x5982;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token comment">//&#x4E00;&#x4E2A;JSON&#x683C;&#x5F0F;&#x7684;&#x7528;&#x6237;&#x5217;&#x8868;&#x5B57;&#x7B26;&#x4E32;</span>
String jsonStr<span class="token operator">=</span><span class="token string">&apos;[{&quot;name&quot;:&quot;Jack&quot;},{&quot;name&quot;:&quot;Rose&quot;}]&apos;</span><span class="token punctuation">;</span>
<span class="token comment">//&#x5C06;JSON&#x5B57;&#x7B26;&#x4E32;&#x8F6C;&#x4E3A;Dart&#x5BF9;&#x8C61;(&#x6B64;&#x5904;&#x662F;List)</span>
List items<span class="token operator">=</span>json<span class="token punctuation">.</span><span class="token function">decode</span><span class="token punctuation">(</span>jsonStr<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">//&#x8F93;&#x51FA;&#x7B2C;&#x4E00;&#x4E2A;&#x7528;&#x6237;&#x7684;&#x59D3;&#x540D;</span>
<span class="token function">print</span><span class="token punctuation">(</span>items<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token string">&quot;name&quot;</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
<p>&#x901A;&#x8FC7;json.decode() &#x5C06;JSON&#x5B57;&#x7B26;&#x4E32;&#x8F6C;&#x4E3A;List/Map&#x7684;&#x65B9;&#x6CD5;&#x6BD4;&#x8F83;&#x7B80;&#x5355;&#xFF0C;&#x5B83;&#x6CA1;&#x6709;&#x5916;&#x90E8;&#x4F9D;&#x8D56;&#x6216;&#x5176;&#x5B83;&#x7684;&#x8BBE;&#x7F6E;&#xFF0C;&#x5BF9;&#x4E8E;&#x5C0F;&#x9879;&#x76EE;&#x5F88;&#x65B9;&#x4FBF;&#x3002;&#x4F46;&#x5F53;&#x9879;&#x76EE;&#x53D8;&#x5927;&#x65F6;&#xFF0C;&#x8FD9;&#x79CD;&#x624B;&#x52A8;&#x7F16;&#x5199;&#x5E8F;&#x5217;&#x5316;&#x903B;&#x8F91;&#x53EF;&#x80FD;&#x53D8;&#x5F97;&#x96BE;&#x4EE5;&#x7BA1;&#x7406;&#x4E14;&#x5BB9;&#x6613;&#x51FA;&#x9519;&#xFF0C;&#x4F8B;&#x5982;&#x6709;&#x5982;&#x4E0B;JSON:</p>
<pre class="language-"><code class="lang-json"><span class="token punctuation">{</span>
  <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;John Smith&quot;</span><span class="token punctuation">,</span>
  <span class="token property">&quot;email&quot;</span><span class="token operator">:</span> <span class="token string">&quot;john@example.com&quot;</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x8C03;&#x7528;<code>json.decode</code>&#x65B9;&#x6CD5;&#x6765;&#x89E3;&#x7801;JSON &#xFF0C;&#x4F7F;&#x7528;JSON&#x5B57;&#x7B26;&#x4E32;&#x4F5C;&#x4E3A;&#x53C2;&#x6570;:</p>
<pre class="language-"><code class="lang-dart">Map<span class="token operator">&lt;</span>String<span class="token punctuation">,</span> <span class="token keyword">dynamic</span><span class="token operator">&gt;</span> user <span class="token operator">=</span> json<span class="token punctuation">.</span><span class="token function">decode</span><span class="token punctuation">(</span>json<span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&apos;Howdy, ${user[&apos;</span>name<span class="token string">&apos;]}!&apos;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&apos;We sent the verification link to ${user[&apos;</span>email<span class="token string">&apos;]}.&apos;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
<p>&#x7531;&#x4E8E;<code>json.decode()</code>&#x4EC5;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;<code>Map<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>String,</span> <span class="token attr-name">dynamic</span><span class="token punctuation">&gt;</span></span></code>&#xFF0C;&#x8FD9;&#x610F;&#x5473;&#x7740;&#x76F4;&#x5230;&#x8FD0;&#x884C;&#x65F6;&#x6211;&#x4EEC;&#x624D;&#x77E5;&#x9053;&#x503C;&#x7684;&#x7C7B;&#x578B;&#x3002; &#x901A;&#x8FC7;&#x8FD9;&#x79CD;&#x65B9;&#x6CD5;&#xFF0C;&#x6211;&#x4EEC;&#x5931;&#x53BB;&#x4E86;&#x5927;&#x90E8;&#x5206;&#x9759;&#x6001;&#x7C7B;&#x578B;&#x8BED;&#x8A00;&#x7279;&#x6027;&#xFF1A;&#x7C7B;&#x578B;&#x5B89;&#x5168;&#x3001;&#x81EA;&#x52A8;&#x8865;&#x5168;&#x548C;&#x6700;&#x91CD;&#x8981;&#x7684;&#x7F16;&#x8BD1;&#x65F6;&#x5F02;&#x5E38;&#x3002;&#x8FD9;&#x6837;&#x4E00;&#x6765;&#xFF0C;&#x6211;&#x4EEC;&#x7684;&#x4EE3;&#x7801;&#x53EF;&#x80FD;&#x4F1A;&#x53D8;&#x5F97;&#x975E;&#x5E38;&#x5BB9;&#x6613;&#x51FA;&#x9519;&#x3002;&#x4F8B;&#x5982;&#xFF0C;&#x5F53;&#x6211;&#x4EEC;&#x8BBF;&#x95EE;<code>name</code>&#x6216;<code>email</code>&#x5B57;&#x6BB5;&#x65F6;&#xFF0C;&#x6211;&#x4EEC;&#x8F93;&#x5165;&#x7684;&#x5F88;&#x5FEB;&#xFF0C;&#x5BFC;&#x81F4;&#x5B57;&#x6BB5;&#x540D;&#x6253;&#x9519;&#x4E86;&#x3002;&#x4F46;&#x7531;&#x4E8E;&#x8FD9;&#x4E2A;JSON&#x5728;map&#x7ED3;&#x6784;&#x4E2D;&#xFF0C;&#x6240;&#x4EE5;&#x7F16;&#x8BD1;&#x5668;&#x4E0D;&#x77E5;&#x9053;&#x8FD9;&#x4E2A;&#x9519;&#x8BEF;&#x7684;&#x5B57;&#x6BB5;&#x540D;&#xFF0C;&#x6240;&#x4EE5;&#x7F16;&#x8BD1;&#x65F6;&#x4E0D;&#x4F1A;&#x62A5;&#x9519;&#x3002;</p>
<p>&#x5176;&#x5B9E;&#xFF0C;&#x8FD9;&#x4E2A;&#x95EE;&#x9898;&#x5728;&#x5F88;&#x591A;&#x5E73;&#x53F0;&#x4E0A;&#x90FD;&#x4F1A;&#x9047;&#x5230;&#xFF0C;&#x800C;&#x4E5F;&#x65E9;&#x5C31;&#x6709;&#x4E86;&#x597D;&#x7684;&#x89E3;&#x51B3;&#x65B9;&#x6CD5;&#x5373;&#x201C;Json Model&#x5316;&#x201D;&#xFF0C;&#x5177;&#x4F53;&#x505A;&#x6CD5;&#x5C31;&#x662F;&#xFF0C;&#x901A;&#x8FC7;&#x9884;&#x5B9A;&#x4E49;&#x4E00;&#x4E9B;&#x4E0E;Json&#x7ED3;&#x6784;&#x5BF9;&#x5E94;&#x7684;Model&#x7C7B;&#xFF0C;&#x7136;&#x540E;&#x5728;&#x8BF7;&#x6C42;&#x5230;&#x6570;&#x636E;&#x540E;&#x518D;&#x52A8;&#x6001;&#x6839;&#x636E;&#x6570;&#x636E;&#x521B;&#x5EFA;&#x51FA;Model&#x7C7B;&#x7684;&#x5B9E;&#x4F8B;&#x3002;&#x8FD9;&#x6837;&#x4E00;&#x6765;&#xFF0C;&#x5728;&#x5F00;&#x53D1;&#x9636;&#x6BB5;&#x6211;&#x4EEC;&#x4F7F;&#x7528;&#x7684;&#x662F;Model&#x7C7B;&#x7684;&#x5B9E;&#x4F8B;&#xFF0C;&#x800C;&#x4E0D;&#x518D;&#x662F;Map/List&#xFF0C;&#x8FD9;&#x6837;&#x8BBF;&#x95EE;&#x5185;&#x90E8;&#x5C5E;&#x6027;&#x65F6;&#x5C31;&#x4E0D;&#x4F1A;&#x53D1;&#x751F;&#x62FC;&#x5199;&#x9519;&#x8BEF;&#x3002;&#x4F8B;&#x5982;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x5F15;&#x5165;&#x4E00;&#x4E2A;&#x7B80;&#x5355;&#x7684;&#x6A21;&#x578B;&#x7C7B;(Model class)&#x6765;&#x89E3;&#x51B3;&#x524D;&#x9762;&#x63D0;&#x5230;&#x7684;&#x95EE;&#x9898;&#xFF0C;&#x6211;&#x4EEC;&#x79F0;&#x4E4B;&#x4E3A;<code>User</code>&#x3002;&#x5728;User&#x7C7B;&#x5185;&#x90E8;&#xFF0C;&#x6211;&#x4EEC;&#x6709;&#xFF1A;</p>
<ul>
<li>&#x4E00;&#x4E2A;<code>User.fromJson</code> &#x6784;&#x9020;&#x51FD;&#x6570;, &#x7528;&#x4E8E;&#x4ECE;&#x4E00;&#x4E2A;map&#x6784;&#x9020;&#x51FA;&#x4E00;&#x4E2A; <code>User</code>&#x5B9E;&#x4F8B; map structure</li>
<li>&#x4E00;&#x4E2A;<code>toJson</code> &#x65B9;&#x6CD5;, &#x5C06; <code>User</code> &#x5B9E;&#x4F8B;&#x8F6C;&#x5316;&#x4E3A;&#x4E00;&#x4E2A;map.</li>
</ul>
<p>&#x8FD9;&#x6837;&#xFF0C;&#x8C03;&#x7528;&#x4EE3;&#x7801;&#x73B0;&#x5728;&#x53EF;&#x4EE5;&#x5177;&#x6709;&#x7C7B;&#x578B;&#x5B89;&#x5168;&#x3001;&#x81EA;&#x52A8;&#x8865;&#x5168;&#x5B57;&#x6BB5;&#xFF08;name&#x548C;email&#xFF09;&#x4EE5;&#x53CA;&#x7F16;&#x8BD1;&#x65F6;&#x5F02;&#x5E38;&#x3002;&#x5982;&#x679C;&#x6211;&#x4EEC;&#x5C06;&#x62FC;&#x5199;&#x9519;&#x8BEF;&#x5B57;&#x6BB5;&#x89C6;&#x4E3A;<code>int</code>&#x7C7B;&#x578B;&#x800C;&#x4E0D;&#x662F;<code>String</code>&#xFF0C; &#x90A3;&#x4E48;&#x6211;&#x4EEC;&#x7684;&#x4EE3;&#x7801;&#x5C31;&#x4E0D;&#x4F1A;&#x901A;&#x8FC7;&#x7F16;&#x8BD1;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x5728;&#x8FD0;&#x884C;&#x65F6;&#x5D29;&#x6E83;&#x3002;</p>
<p><strong>user.dart</strong></p>
<pre class="language-"><code class="lang-dart"><span class="token keyword">class</span> <span class="token class-name">User</span> <span class="token punctuation">{</span>
  <span class="token keyword">final</span> String name<span class="token punctuation">;</span>
  <span class="token keyword">final</span> String email<span class="token punctuation">;</span>

  <span class="token function">User</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>name<span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">.</span>email<span class="token punctuation">)</span><span class="token punctuation">;</span>

  User<span class="token punctuation">.</span><span class="token function">fromJson</span><span class="token punctuation">(</span>Map<span class="token operator">&lt;</span>String<span class="token punctuation">,</span> <span class="token keyword">dynamic</span><span class="token operator">&gt;</span> json<span class="token punctuation">)</span>
      <span class="token punctuation">:</span> name <span class="token operator">=</span> json<span class="token punctuation">[</span><span class="token string">&apos;name&apos;</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
        email <span class="token operator">=</span> json<span class="token punctuation">[</span><span class="token string">&apos;email&apos;</span><span class="token punctuation">]</span><span class="token punctuation">;</span>

  Map<span class="token operator">&lt;</span>String<span class="token punctuation">,</span> <span class="token keyword">dynamic</span><span class="token operator">&gt;</span> <span class="token function">toJson</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span>
    <span class="token operator">&lt;</span>String<span class="token punctuation">,</span> <span class="token keyword">dynamic</span><span class="token operator">&gt;</span><span class="token punctuation">{</span>
      <span class="token string">&apos;name&apos;</span><span class="token punctuation">:</span> name<span class="token punctuation">,</span>
      <span class="token string">&apos;email&apos;</span><span class="token punctuation">:</span> email<span class="token punctuation">,</span>
    <span class="token punctuation">}</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x73B0;&#x5728;&#xFF0C;&#x5E8F;&#x5217;&#x5316;&#x903B;&#x8F91;&#x79FB;&#x5230;&#x4E86;&#x6A21;&#x578B;&#x672C;&#x8EAB;&#x5185;&#x90E8;&#x3002;&#x91C7;&#x7528;&#x8FD9;&#x79CD;&#x65B0;&#x65B9;&#x6CD5;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x975E;&#x5E38;&#x5BB9;&#x6613;&#x5730;&#x53CD;&#x5E8F;&#x5217;&#x5316;user.</p>
<pre class="language-"><code class="lang-dart">Map userMap <span class="token operator">=</span> json<span class="token punctuation">.</span><span class="token function">decode</span><span class="token punctuation">(</span>json<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">var</span> user <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">User<span class="token punctuation">.</span>fromJson</span><span class="token punctuation">(</span>userMap<span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&apos;Howdy, ${user.name}!&apos;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&apos;We sent the verification link to ${user.email}.&apos;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
<p>&#x8981;&#x5E8F;&#x5217;&#x5316;&#x4E00;&#x4E2A;user&#xFF0C;&#x6211;&#x4EEC;&#x53EA;&#x662F;&#x5C06;&#x8BE5;<code>User</code>&#x5BF9;&#x8C61;&#x4F20;&#x9012;&#x7ED9;&#x8BE5;<code>json.encode</code>&#x65B9;&#x6CD5;&#x3002;&#x6211;&#x4EEC;&#x4E0D;&#x9700;&#x8981;&#x624B;&#x52A8;&#x8C03;&#x7528;<code>toJson</code>&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#xFF0C;&#x56E0;&#x4E3A;`JSON.encode&#x5185;&#x90E8;&#x4F1A;&#x81EA;&#x52A8;&#x8C03;&#x7528;&#x3002;</p>
<pre class="language-"><code class="lang-dart">String json <span class="token operator">=</span> json<span class="token punctuation">.</span><span class="token function">encode</span><span class="token punctuation">(</span>user<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
<p>&#x8FD9;&#x6837;&#xFF0C;&#x8C03;&#x7528;&#x4EE3;&#x7801;&#x5C31;&#x4E0D;&#x7528;&#x62C5;&#x5FC3;JSON&#x5E8F;&#x5217;&#x5316;&#x4E86;&#xFF0C;&#x4F46;&#x662F;&#xFF0C;Model&#x7C7B;&#x8FD8;&#x662F;&#x5FC5;&#x987B;&#x7684;&#x3002;&#x5728;&#x5B9E;&#x8DF5;&#x4E2D;&#xFF0C;<code>User.fromJson</code>&#x548C;<code>User.toJson</code>&#x65B9;&#x6CD5;&#x90FD;&#x9700;&#x8981;&#x5355;&#x5143;&#x6D4B;&#x8BD5;&#x5230;&#x4F4D;&#xFF0C;&#x4EE5;&#x9A8C;&#x8BC1;&#x6B63;&#x786E;&#x7684;&#x884C;&#x4E3A;&#x3002;</p>
<p>&#x53E6;&#x5916;&#xFF0C;&#x5B9E;&#x9645;&#x573A;&#x666F;&#x4E2D;&#xFF0C;JSON&#x5BF9;&#x8C61;&#x5F88;&#x5C11;&#x4F1A;&#x8FD9;&#x4E48;&#x7B80;&#x5355;&#xFF0C;&#x5D4C;&#x5957;&#x7684;JSON&#x5BF9;&#x8C61;&#x5E76;&#x4E0D;&#x7F55;&#x89C1;&#xFF0C;&#x5982;&#x679C;&#x6709;&#x4EC0;&#x4E48;&#x80FD;&#x4E3A;&#x6211;&#x4EEC;&#x81EA;&#x52A8;&#x5904;&#x7406;JSON&#x5E8F;&#x5217;&#x5316;&#xFF0C;&#x90A3;&#x5C06;&#x4F1A;&#x975E;&#x5E38;&#x597D;&#x3002;&#x5E78;&#x8FD0;&#x7684;&#x662F;&#xFF0C;&#x6709;&#xFF01;</p>
<h3 id="&#x81EA;&#x52A8;&#x751F;&#x6210;model">&#x81EA;&#x52A8;&#x751F;&#x6210;Model</h3>
<p>&#x5C3D;&#x7BA1;&#x8FD8;&#x6709;&#x5176;&#x4ED6;&#x5E93;&#x53EF;&#x7528;&#xFF0C;&#x4F46;&#x5728;&#x672C;&#x4E66;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x4ECB;&#x7ECD;&#x4E00;&#x4E0B;&#x5B98;&#x65B9;&#x63A8;&#x8350;&#x7684;<a href="https://pub.dartlang.org/packages/json_serializable" target="_blank">json_serializable package</a>&#x5305;&#x3002; &#x5B83;&#x662F;&#x4E00;&#x4E2A;&#x81EA;&#x52A8;&#x5316;&#x7684;&#x6E90;&#x4EE3;&#x7801;&#x751F;&#x6210;&#x5668;&#xFF0C;&#x53EF;&#x4EE5;&#x5728;&#x5F00;&#x53D1;&#x9636;&#x6BB5;&#x4E3A;&#x6211;&#x4EEC;&#x751F;&#x6210;JSON&#x5E8F;&#x5217;&#x5316;&#x6A21;&#x677F;&#xFF0C;&#x8FD9;&#x6837;&#x4E00;&#x6765;&#xFF0C;&#x7531;&#x4E8E;&#x5E8F;&#x5217;&#x5316;&#x4EE3;&#x7801;&#x4E0D;&#x518D;&#x7531;&#x6211;&#x4EEC;&#x624B;&#x5199;&#x548C;&#x7EF4;&#x62A4;&#xFF0C;&#x6211;&#x4EEC;&#x5C06;&#x8FD0;&#x884C;&#x65F6;&#x4EA7;&#x751F;JSON&#x5E8F;&#x5217;&#x5316;&#x5F02;&#x5E38;&#x7684;&#x98CE;&#x9669;&#x964D;&#x81F3;&#x6700;&#x4F4E;&#x3002;</p>
<h3 id="&#x5728;&#x9879;&#x76EE;&#x4E2D;&#x8BBE;&#x7F6E;jsonserializable">&#x5728;&#x9879;&#x76EE;&#x4E2D;&#x8BBE;&#x7F6E;json_serializable</h3>
<p>&#x8981;&#x5305;&#x542B;<code>json_serializable</code>&#x5230;&#x6211;&#x4EEC;&#x7684;&#x9879;&#x76EE;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x4E00;&#x4E2A;&#x5E38;&#x89C4;&#x548C;&#x4E24;&#x4E2A;<strong>&#x5F00;&#x53D1;&#x4F9D;&#x8D56;</strong>&#x9879;&#x3002;&#x7B80;&#x800C;&#x8A00;&#x4E4B;&#xFF0C;<strong>&#x5F00;&#x53D1;&#x4F9D;&#x8D56;&#x9879;</strong>&#x662F;&#x4E0D;&#x5305;&#x542B;&#x5728;&#x6211;&#x4EEC;&#x7684;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x6E90;&#x4EE3;&#x7801;&#x4E2D;&#x7684;&#x4F9D;&#x8D56;&#x9879;&#xFF0C;&#x5B83;&#x662F;&#x5F00;&#x53D1;&#x8FC7;&#x7A0B;&#x4E2D;&#x7684;&#x4E00;&#x4E9B;&#x8F85;&#x52A9;&#x5DE5;&#x5177;&#x3001;&#x811A;&#x672C;&#xFF0C;&#x548C;node&#x4E2D;&#x7684;&#x5F00;&#x53D1;&#x4F9D;&#x8D56;&#x9879;&#x76F8;&#x4F3C;&#x3002;</p>
<p><strong>pubspec.yaml</strong></p>
<pre class="language-"><code class="lang-yaml"><span class="token key atrule">dependencies</span><span class="token punctuation">:</span>
  <span class="token comment"># Your other regular dependencies here</span>
  <span class="token key atrule">json_annotation</span><span class="token punctuation">:</span> ^2.0.0

<span class="token key atrule">dev_dependencies</span><span class="token punctuation">:</span>
  <span class="token comment"># Your other dev_dependencies here</span>
  <span class="token key atrule">build_runner</span><span class="token punctuation">:</span> ^1.0.0
  <span class="token key atrule">json_serializable</span><span class="token punctuation">:</span> ^2.0.0
</code></pre>
<p>&#x5728;&#x60A8;&#x7684;&#x9879;&#x76EE;&#x6839;&#x6587;&#x4EF6;&#x5939;&#x4E2D;&#x8FD0;&#x884C; <code>flutter packages get</code> (&#x6216;&#x8005;&#x5728;&#x7F16;&#x8F91;&#x5668;&#x4E2D;&#x70B9;&#x51FB; &#x201C;Packages Get&#x201D;) &#x4EE5;&#x5728;&#x9879;&#x76EE;&#x4E2D;&#x4F7F;&#x7528;&#x8FD9;&#x4E9B;&#x65B0;&#x7684;&#x4F9D;&#x8D56;&#x9879;.</p>
<h3 id="&#x4EE5;jsonserializable&#x7684;&#x65B9;&#x5F0F;&#x521B;&#x5EFA;model&#x7C7B;">&#x4EE5;json_serializable&#x7684;&#x65B9;&#x5F0F;&#x521B;&#x5EFA;model&#x7C7B;</h3>
<p>&#x8BA9;&#x6211;&#x4EEC;&#x770B;&#x770B;&#x5982;&#x4F55;&#x5C06;&#x6211;&#x4EEC;&#x7684;<code>User</code>&#x7C7B;&#x8F6C;&#x6362;&#x4E3A;&#x4E00;&#x4E2A;<code>json_serializable</code>&#x3002;&#x4E3A;&#x4E86;&#x7B80;&#x5355;&#x8D77;&#x89C1;&#xFF0C;&#x6211;&#x4EEC;&#x4F7F;&#x7528;&#x524D;&#x9762;&#x793A;&#x4F8B;&#x4E2D;&#x7684;&#x7B80;&#x5316;JSON model&#x3002;</p>
<p><strong>user.dart</strong></p>
<pre class="language-"><code class="lang-dart"><span class="token keyword">import</span> <span class="token string">&apos;package:json_annotation/json_annotation.dart&apos;</span><span class="token punctuation">;</span>

<span class="token comment">// user.g.dart &#x5C06;&#x5728;&#x6211;&#x4EEC;&#x8FD0;&#x884C;&#x751F;&#x6210;&#x547D;&#x4EE4;&#x540E;&#x81EA;&#x52A8;&#x751F;&#x6210;</span>
<span class="token keyword">part</span> <span class="token string">&apos;user.g.dart&apos;</span><span class="token punctuation">;</span>

<span class="token comment">///&#x8FD9;&#x4E2A;&#x6807;&#x6CE8;&#x662F;&#x544A;&#x8BC9;&#x751F;&#x6210;&#x5668;&#xFF0C;&#x8FD9;&#x4E2A;&#x7C7B;&#x662F;&#x9700;&#x8981;&#x751F;&#x6210;Model&#x7C7B;&#x7684;</span>
<span class="token metadata symbol">@JsonSerializable</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

<span class="token keyword">class</span> <span class="token class-name">User</span><span class="token punctuation">{</span>
  <span class="token function">User</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>name<span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">.</span>email<span class="token punctuation">)</span><span class="token punctuation">;</span>

  String name<span class="token punctuation">;</span>
  String email<span class="token punctuation">;</span>
  <span class="token comment">//&#x4E0D;&#x540C;&#x7684;&#x7C7B;&#x4F7F;&#x7528;&#x4E0D;&#x540C;&#x7684;mixin&#x5373;&#x53EF;</span>
  <span class="token keyword">factory</span> User<span class="token punctuation">.</span><span class="token function">fromJson</span><span class="token punctuation">(</span>Map<span class="token operator">&lt;</span>String<span class="token punctuation">,</span> <span class="token keyword">dynamic</span><span class="token operator">&gt;</span> json<span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span> _$<span class="token function">UserFromJson</span><span class="token punctuation">(</span>json<span class="token punctuation">)</span><span class="token punctuation">;</span>
  Map<span class="token operator">&lt;</span>String<span class="token punctuation">,</span> <span class="token keyword">dynamic</span><span class="token operator">&gt;</span> <span class="token function">toJson</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span> _$<span class="token function">UserToJson</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  
<span class="token punctuation">}</span>
</code></pre>
<p>&#x6709;&#x4E86;&#x4E0A;&#x9762;&#x7684;&#x8BBE;&#x7F6E;&#xFF0C;&#x6E90;&#x7801;&#x751F;&#x6210;&#x5668;&#x5C06;&#x751F;&#x6210;&#x7528;&#x4E8E;&#x5E8F;&#x5217;&#x5316;<code>name</code>&#x548C;<code>email</code>&#x5B57;&#x6BB5;&#x7684;JSON&#x4EE3;&#x7801;&#x3002;</p>
<p>&#x5982;&#x679C;&#x9700;&#x8981;&#xFF0C;&#x81EA;&#x5B9A;&#x4E49;&#x547D;&#x540D;&#x7B56;&#x7565;&#x4E5F;&#x5F88;&#x5BB9;&#x6613;&#x3002;&#x4F8B;&#x5982;&#xFF0C;&#x5982;&#x679C;&#x6211;&#x4EEC;&#x6B63;&#x5728;&#x4F7F;&#x7528;&#x7684;API&#x8FD4;&#x56DE;&#x5E26;&#x6709;<em>snake_case</em>&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x4F46;&#x6211;&#x4EEC;&#x60F3;&#x5728;&#x6211;&#x4EEC;&#x7684;&#x6A21;&#x578B;&#x4E2D;&#x4F7F;&#x7528;<em>lowerCamelCase</em>&#xFF0C; &#x90A3;&#x4E48;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;@JsonKey&#x6807;&#x6CE8;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token comment">//&#x663E;&#x5F0F;&#x5173;&#x8054;JSON&#x5B57;&#x6BB5;&#x540D;&#x4E0E;Model&#x5C5E;&#x6027;&#x7684;&#x5BF9;&#x5E94;&#x5173;&#x7CFB; </span>
<span class="token metadata symbol">@JsonKey</span><span class="token punctuation">(</span>name<span class="token punctuation">:</span> <span class="token string">&apos;registration_date_millis&apos;</span><span class="token punctuation">)</span>
<span class="token keyword">final</span> int registrationDateMillis<span class="token punctuation">;</span>
</code></pre>
<h3 id="&#x8FD0;&#x884C;&#x4EE3;&#x7801;&#x751F;&#x6210;&#x7A0B;&#x5E8F;">&#x8FD0;&#x884C;&#x4EE3;&#x7801;&#x751F;&#x6210;&#x7A0B;&#x5E8F;</h3>
<p><code>json_serializable</code>&#x7B2C;&#x4E00;&#x6B21;&#x521B;&#x5EFA;&#x7C7B;&#x65F6;&#xFF0C;&#x60A8;&#x4F1A;&#x770B;&#x5230;&#x4E0E;&#x56FE;11-4&#x7C7B;&#x4F3C;&#x7684;&#x9519;&#x8BEF;&#x3002;</p>
<p><img src="https://pcdn.flutterchina.club/imgs/11-4.png" alt="ide_warning"></p>
<p>&#x8FD9;&#x4E9B;&#x9519;&#x8BEF;&#x662F;&#x5B8C;&#x5168;&#x6B63;&#x5E38;&#x7684;&#xFF0C;&#x8FD9;&#x662F;&#x56E0;&#x4E3A;Model&#x7C7B;&#x7684;&#x751F;&#x6210;&#x4EE3;&#x7801;&#x8FD8;&#x4E0D;&#x5B58;&#x5728;&#x3002;&#x4E3A;&#x4E86;&#x89E3;&#x51B3;&#x8FD9;&#x4E2A;&#x95EE;&#x9898;&#xFF0C;&#x6211;&#x4EEC;&#x5FC5;&#x987B;&#x8FD0;&#x884C;&#x4EE3;&#x7801;&#x751F;&#x6210;&#x5668;&#x6765;&#x4E3A;&#x6211;&#x4EEC;&#x751F;&#x6210;&#x5E8F;&#x5217;&#x5316;&#x6A21;&#x677F;&#x3002;&#x6709;&#x4E24;&#x79CD;&#x8FD0;&#x884C;&#x4EE3;&#x7801;&#x751F;&#x6210;&#x5668;&#x7684;&#x65B9;&#x6CD5;&#xFF1A;</p>
<h4 id="&#x4E00;&#x6B21;&#x6027;&#x751F;&#x6210;">&#x4E00;&#x6B21;&#x6027;&#x751F;&#x6210;</h4>
<p>&#x901A;&#x8FC7;&#x5728;&#x6211;&#x4EEC;&#x7684;&#x9879;&#x76EE;&#x6839;&#x76EE;&#x5F55;&#x4E0B;&#x8FD0;&#x884C;:</p>
<pre class="language-"><code class="lang-shell">flutter packages pub run build_runner build
</code></pre>
<p> &#x8FD9;&#x89E6;&#x53D1;&#x4E86;&#x4E00;&#x6B21;&#x6027;&#x6784;&#x5EFA;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5728;&#x9700;&#x8981;&#x65F6;&#x4E3A;&#x6211;&#x4EEC;&#x7684;Model&#x751F;&#x6210;json&#x5E8F;&#x5217;&#x5316;&#x4EE3;&#x7801;&#xFF0C;&#x5B83;&#x901A;&#x8FC7;&#x6211;&#x4EEC;&#x7684;&#x6E90;&#x6587;&#x4EF6;&#xFF0C;&#x627E;&#x51FA;&#x9700;&#x8981;&#x751F;&#x6210;Model&#x7C7B;&#x7684;&#x6E90;&#x6587;&#x4EF6;&#xFF08;&#x5305;&#x542B;@JsonSerializable&#x6807;&#x6CE8;&#x7684;&#xFF09;&#x6765;&#x751F;&#x6210;&#x5BF9;&#x5E94;&#x7684;.g.dart&#x6587;&#x4EF6;&#x3002;&#x4E00;&#x4E2A;&#x597D;&#x7684;&#x5EFA;&#x8BAE;&#x662F;&#x5C06;&#x6240;&#x6709;Model&#x7C7B;&#x653E;&#x5728;&#x4E00;&#x4E2A;&#x5355;&#x72EC;&#x7684;&#x76EE;&#x5F55;&#x4E0B;&#xFF0C;&#x7136;&#x540E;&#x5728;&#x8BE5;&#x76EE;&#x5F55;&#x4E0B;&#x6267;&#x884C;&#x547D;&#x4EE4;&#x3002;</p>
<p>&#x867D;&#x7136;&#x8FD9;&#x975E;&#x5E38;&#x65B9;&#x4FBF;&#xFF0C;&#x4F46;&#x5982;&#x679C;&#x6211;&#x4EEC;&#x4E0D;&#x9700;&#x8981;&#x6BCF;&#x6B21;&#x5728;Model&#x7C7B;&#x4E2D;&#x8FDB;&#x884C;&#x66F4;&#x6539;&#x65F6;&#x90FD;&#x8981;&#x624B;&#x52A8;&#x8FD0;&#x884C;&#x6784;&#x5EFA;&#x547D;&#x4EE4;&#x7684;&#x8BDD;&#x4F1A;&#x66F4;&#x597D;&#x3002;</p>
<h4 id="&#x6301;&#x7EED;&#x751F;&#x6210;">&#x6301;&#x7EED;&#x751F;&#x6210;</h4>
<p>&#x4F7F;&#x7528;<em>watcher</em>&#x53EF;&#x4EE5;&#x4F7F;&#x6211;&#x4EEC;&#x7684;&#x6E90;&#x4EE3;&#x7801;&#x751F;&#x6210;&#x7684;&#x8FC7;&#x7A0B;&#x66F4;&#x52A0;&#x65B9;&#x4FBF;&#x3002;&#x5B83;&#x4F1A;&#x76D1;&#x89C6;&#x6211;&#x4EEC;&#x9879;&#x76EE;&#x4E2D;&#x6587;&#x4EF6;&#x7684;&#x53D8;&#x5316;&#xFF0C;&#x5E76;&#x5728;&#x9700;&#x8981;&#x65F6;&#x81EA;&#x52A8;&#x6784;&#x5EFA;&#x5FC5;&#x8981;&#x7684;&#x6587;&#x4EF6;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;<code>flutter packages pub run build_runner watch</code>&#x5728;&#x9879;&#x76EE;&#x6839;&#x76EE;&#x5F55;&#x4E0B;&#x8FD0;&#x884C;&#x6765;&#x542F;&#x52A8;<em>watcher</em>&#x3002;&#x53EA;&#x9700;&#x542F;&#x52A8;&#x4E00;&#x6B21;&#x89C2;&#x5BDF;&#x5668;&#xFF0C;&#x7136;&#x540E;&#x5B83;&#x5C31;&#x4F1A;&#x5728;&#x540E;&#x53F0;&#x8FD0;&#x884C;&#xFF0C;&#x8FD9;&#x662F;&#x5B89;&#x5168;&#x7684;&#x3002;</p>
<h3 id="&#x81EA;&#x52A8;&#x5316;&#x751F;&#x6210;&#x6A21;&#x677F;">&#x81EA;&#x52A8;&#x5316;&#x751F;&#x6210;&#x6A21;&#x677F;</h3>
<p>&#x4E0A;&#x9762;&#x7684;&#x65B9;&#x6CD5;&#x6709;&#x4E00;&#x4E2A;&#x6700;&#x5927;&#x7684;&#x95EE;&#x9898;&#x5C31;&#x662F;&#x8981;&#x4E3A;&#x6BCF;&#x4E00;&#x4E2A;json&#x5199;&#x6A21;&#x677F;&#xFF0C;&#x8FD9;&#x662F;&#x6BD4;&#x8F83;&#x67AF;&#x71E5;&#x7684;&#x3002;&#x5982;&#x679C;&#x6709;&#x4E00;&#x4E2A;&#x5DE5;&#x5177;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x6839;&#x636E;JSON&#x6587;&#x672C;&#x751F;&#x6210;&#x6A21;&#x677F;&#xFF0C;&#x90A3;&#x6211;&#x4EEC;&#x5C31;&#x80FD;&#x5F7B;&#x5E95;&#x89E3;&#x653E;&#x53CC;&#x624B;&#x4E86;&#x3002;&#x7B14;&#x8005;&#x81EA;&#x5DF1;&#x7528;dart&#x5B9E;&#x73B0;&#x4E86;&#x4E00;&#x4E2A;&#x811A;&#x672C;&#xFF0C;&#x5B83;&#x53EF;&#x4EE5;&#x81EA;&#x52A8;&#x751F;&#x6210;&#x6A21;&#x677F;&#xFF0C;&#x5E76;&#x76F4;&#x63A5;&#x5C06;JSON&#x8F6C;&#x4E3A;Model&#x7C7B;&#xFF0C;&#x4E0B;&#x9762;&#x6211;&#x4EEC;&#x770B;&#x770B;&#x600E;&#x4E48;&#x505A;&#xFF1A;</p>
<ol>
<li><p>&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&quot;&#x6A21;&#x677F;&#x7684;&#x6A21;&#x677F;&quot;&#xFF0C;&#x540D;&#x4E3A;&quot;template.dart&quot;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token keyword">import</span> <span class="token string">&apos;package:json_annotation/json_annotation.dart&apos;</span><span class="token punctuation">;</span>
<span class="token operator">%</span>t
<span class="token keyword">part</span> <span class="token string">&apos;%s.g.dart&apos;</span><span class="token punctuation">;</span>
<span class="token metadata symbol">@JsonSerializable</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">class</span> <span class="token operator">%</span>s <span class="token punctuation">{</span>
    <span class="token operator">%</span><span class="token function">s</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token operator">%</span>s
    <span class="token keyword">factory</span> <span class="token operator">%</span>s<span class="token punctuation">.</span><span class="token function">fromJson</span><span class="token punctuation">(</span>Map<span class="token operator">&lt;</span>String<span class="token punctuation">,</span><span class="token keyword">dynamic</span><span class="token operator">&gt;</span> json<span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span> _$<span class="token operator">%</span><span class="token function">sFromJson</span><span class="token punctuation">(</span>json<span class="token punctuation">)</span><span class="token punctuation">;</span>
    Map<span class="token operator">&lt;</span>String<span class="token punctuation">,</span> <span class="token keyword">dynamic</span><span class="token operator">&gt;</span> <span class="token function">toJson</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span> _$<span class="token operator">%</span><span class="token function">sToJson</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x6A21;&#x677F;&#x4E2D;&#x7684;&#x201C;%t&#x201D;&#x3001;&#x201C;%s&#x201D;&#x4E3A;&#x5360;&#x4F4D;&#x7B26;&#xFF0C;&#x5C06;&#x5728;&#x811A;&#x672C;&#x8FD0;&#x884C;&#x65F6;&#x52A8;&#x6001;&#x88AB;&#x66FF;&#x6362;&#x4E3A;&#x5408;&#x9002;&#x7684;&#x5BFC;&#x5165;&#x5934;&#x548C;&#x7C7B;&#x540D;&#x3002;</p>
</li>
<li><p>&#x5199;&#x4E00;&#x4E2A;&#x81EA;&#x52A8;&#x751F;&#x6210;&#x6A21;&#x677F;&#x7684;&#x811A;&#x672C;(mo.dart)&#xFF0C;&#x5B83;&#x53EF;&#x4EE5;&#x6839;&#x636E;&#x6307;&#x5B9A;&#x7684;JSON&#x76EE;&#x5F55;&#xFF0C;&#x904D;&#x5386;&#x751F;&#x6210;&#x6A21;&#x677F;&#xFF0C;&#x5728;&#x751F;&#x6210;&#x65F6;&#x6211;&#x4EEC;&#x5B9A;&#x4E49;&#x4E00;&#x4E9B;&#x89C4;&#x5219;&#xFF1A;</p>
<ul>
<li>&#x5982;&#x679C;JSON&#x6587;&#x4EF6;&#x540D;&#x4EE5;&#x4E0B;&#x5212;&#x7EBF;&#x201C;_&#x201D;&#x5F00;&#x59CB;&#xFF0C;&#x5219;&#x5FFD;&#x7565;&#x6B64;JSON&#x6587;&#x4EF6;&#x3002;</li>
<li>&#x590D;&#x6742;&#x7684;JSON&#x5BF9;&#x8C61;&#x5F80;&#x5F80;&#x4F1A;&#x51FA;&#x73B0;&#x5D4C;&#x5957;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x4E00;&#x4E2A;&#x7279;&#x6B8A;&#x6807;&#x5FD7;&#x6765;&#x624B;&#x52A8;&#x6307;&#x5B9A;&#x5D4C;&#x5957;&#x7684;&#x5BF9;&#x8C61;&#xFF08;&#x540E;&#x9762;&#x4E3E;&#x4F8B;&#xFF09;&#x3002;</li>
</ul>
<p>&#x811A;&#x672C;&#x6211;&#x4EEC;&#x901A;&#x8FC7;Dart&#x6765;&#x5199;&#xFF0C;&#x6E90;&#x7801;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token keyword">import</span> <span class="token string">&apos;dart:convert&apos;</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token string">&apos;dart:io&apos;</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token string">&apos;package:path/path.dart&apos;</span> <span class="token operator">as</span> path<span class="token punctuation">;</span>
<span class="token keyword">const</span> TAG<span class="token operator">=</span><span class="token string">&quot;\$&quot;</span><span class="token punctuation">;</span>
<span class="token keyword">const</span> SRC<span class="token operator">=</span><span class="token string">&quot;./json&quot;</span><span class="token punctuation">;</span> <span class="token comment">//JSON &#x76EE;&#x5F55;</span>
<span class="token keyword">const</span> DIST<span class="token operator">=</span><span class="token string">&quot;lib/models/&quot;</span><span class="token punctuation">;</span> <span class="token comment">//&#x8F93;&#x51FA;model&#x76EE;&#x5F55;</span>

<span class="token keyword">void</span> <span class="token function">walk</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token comment">//&#x904D;&#x5386;JSON&#x76EE;&#x5F55;&#x751F;&#x6210;&#x6A21;&#x677F;</span>
  <span class="token keyword">var</span> src <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Directory</span><span class="token punctuation">(</span>SRC<span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token keyword">var</span> list <span class="token operator">=</span> src<span class="token punctuation">.</span><span class="token function">listSync</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token keyword">var</span> template<span class="token operator">=</span><span class="token keyword">new</span> <span class="token class-name">File</span><span class="token punctuation">(</span><span class="token string">&quot;./template.dart&quot;</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">readAsStringSync</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  File file<span class="token punctuation">;</span>
  list<span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span><span class="token punctuation">(</span>f<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span>FileSystemEntity<span class="token punctuation">.</span><span class="token function">isFileSync</span><span class="token punctuation">(</span>f<span class="token punctuation">.</span>path<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      file <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">File</span><span class="token punctuation">(</span>f<span class="token punctuation">.</span>path<span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token keyword">var</span> paths<span class="token operator">=</span>path<span class="token punctuation">.</span><span class="token function">basename</span><span class="token punctuation">(</span>f<span class="token punctuation">.</span>path<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">split</span><span class="token punctuation">(</span><span class="token string">&quot;.&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      String name<span class="token operator">=</span>paths<span class="token punctuation">.</span>first<span class="token punctuation">;</span>
      <span class="token keyword">if</span><span class="token punctuation">(</span>paths<span class="token punctuation">.</span>last<span class="token punctuation">.</span><span class="token function">toLowerCase</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">!=</span><span class="token string">&quot;json&quot;</span><span class="token operator">||</span>name<span class="token punctuation">.</span><span class="token function">startsWith</span><span class="token punctuation">(</span><span class="token string">&quot;_&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token keyword">return</span> <span class="token punctuation">;</span>
      <span class="token keyword">if</span><span class="token punctuation">(</span>name<span class="token punctuation">.</span><span class="token function">startsWith</span><span class="token punctuation">(</span><span class="token string">&quot;_&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token keyword">return</span><span class="token punctuation">;</span>
      <span class="token comment">//&#x4E0B;&#x9762;&#x751F;&#x6210;&#x6A21;&#x677F;</span>
      <span class="token keyword">var</span> map <span class="token operator">=</span> json<span class="token punctuation">.</span><span class="token function">decode</span><span class="token punctuation">(</span>file<span class="token punctuation">.</span><span class="token function">readAsStringSync</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token comment">//&#x4E3A;&#x4E86;&#x907F;&#x514D;&#x91CD;&#x590D;&#x5BFC;&#x5165;&#x76F8;&#x540C;&#x7684;&#x5305;&#xFF0C;&#x6211;&#x4EEC;&#x7528;Set&#x6765;&#x4FDD;&#x5B58;&#x751F;&#x6210;&#x7684;import&#x8BED;&#x53E5;&#x3002;</span>
      <span class="token keyword">var</span> <span class="token keyword">set</span><span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Set</span><span class="token operator">&lt;</span>String<span class="token operator">&gt;</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      StringBuffer attrs<span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">StringBuffer</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token punctuation">(</span>map <span class="token operator">as</span> Map<span class="token operator">&lt;</span>String<span class="token punctuation">,</span> <span class="token keyword">dynamic</span><span class="token operator">&gt;</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span><span class="token punctuation">(</span>key<span class="token punctuation">,</span> v<span class="token punctuation">)</span> <span class="token punctuation">{</span>
          <span class="token keyword">if</span><span class="token punctuation">(</span>key<span class="token punctuation">.</span><span class="token function">startsWith</span><span class="token punctuation">(</span><span class="token string">&quot;_&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token keyword">return</span> <span class="token punctuation">;</span>
          attrs<span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span><span class="token function">getType</span><span class="token punctuation">(</span>v<span class="token punctuation">,</span><span class="token keyword">set</span><span class="token punctuation">,</span>name<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
          attrs<span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span><span class="token string">&quot; &quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
          attrs<span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span>key<span class="token punctuation">)</span><span class="token punctuation">;</span>
          attrs<span class="token punctuation">.</span><span class="token function">writeln</span><span class="token punctuation">(</span><span class="token string">&quot;;&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
          attrs<span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span><span class="token string">&quot;    &quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      String  className<span class="token operator">=</span>name<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token function">toUpperCase</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">+</span>name<span class="token punctuation">.</span><span class="token function">substring</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token keyword">var</span> dist<span class="token operator">=</span><span class="token function">format</span><span class="token punctuation">(</span>template<span class="token punctuation">,</span><span class="token punctuation">[</span>name<span class="token punctuation">,</span>className<span class="token punctuation">,</span>className<span class="token punctuation">,</span>attrs<span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                                className<span class="token punctuation">,</span>className<span class="token punctuation">,</span>className<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token keyword">var</span> _import<span class="token operator">=</span><span class="token keyword">set</span><span class="token punctuation">.</span><span class="token function">join</span><span class="token punctuation">(</span><span class="token string">&quot;;\r\n&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      _import<span class="token operator">+=</span>_import<span class="token punctuation">.</span>isEmpty<span class="token operator">?</span><span class="token string">&quot;&quot;</span><span class="token punctuation">:</span><span class="token string">&quot;;&quot;</span><span class="token punctuation">;</span>
      dist<span class="token operator">=</span>dist<span class="token punctuation">.</span><span class="token function">replaceFirst</span><span class="token punctuation">(</span><span class="token string">&quot;%t&quot;</span><span class="token punctuation">,</span>_import <span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token comment">//&#x5C06;&#x751F;&#x6210;&#x7684;&#x6A21;&#x677F;&#x8F93;&#x51FA;</span>
      <span class="token keyword">new</span> <span class="token class-name">File</span><span class="token punctuation">(</span><span class="token string">&quot;$DIST$name.dart&quot;</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">writeAsStringSync</span><span class="token punctuation">(</span>dist<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

String <span class="token function">changeFirstChar</span><span class="token punctuation">(</span>String str<span class="token punctuation">,</span> <span class="token punctuation">[</span>bool upper<span class="token operator">=</span><span class="token boolean">true</span><span class="token punctuation">]</span> <span class="token punctuation">)</span><span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token punctuation">(</span>upper<span class="token operator">?</span>str<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token function">toUpperCase</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>str<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token function">toLowerCase</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token operator">+</span>str<span class="token punctuation">.</span><span class="token function">substring</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token comment">//&#x5C06;JSON&#x7C7B;&#x578B;&#x8F6C;&#x4E3A;&#x5BF9;&#x5E94;&#x7684;dart&#x7C7B;&#x578B;</span>
 String <span class="token function">getType</span><span class="token punctuation">(</span>v<span class="token punctuation">,</span>Set<span class="token operator">&lt;</span>String<span class="token operator">&gt;</span> <span class="token keyword">set</span><span class="token punctuation">,</span>String current<span class="token punctuation">)</span><span class="token punctuation">{</span>
  current<span class="token operator">=</span>current<span class="token punctuation">.</span><span class="token function">toLowerCase</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token keyword">if</span><span class="token punctuation">(</span>v <span class="token operator">is</span> bool<span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token string">&quot;bool&quot;</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span><span class="token keyword">else</span> <span class="token keyword">if</span><span class="token punctuation">(</span>v <span class="token operator">is</span> num<span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token string">&quot;num&quot;</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span><span class="token keyword">else</span> <span class="token keyword">if</span><span class="token punctuation">(</span>v <span class="token operator">is</span> Map<span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token string">&quot;Map&lt;String,dynamic&gt;&quot;</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span><span class="token keyword">else</span> <span class="token keyword">if</span><span class="token punctuation">(</span>v <span class="token operator">is</span> List<span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token string">&quot;List&quot;</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span><span class="token keyword">else</span> <span class="token keyword">if</span><span class="token punctuation">(</span>v <span class="token operator">is</span> String<span class="token punctuation">)</span><span class="token punctuation">{</span> <span class="token comment">//&#x5904;&#x7406;&#x7279;&#x6B8A;&#x6807;&#x5FD7;</span>
    <span class="token keyword">if</span><span class="token punctuation">(</span>v<span class="token punctuation">.</span><span class="token function">startsWith</span><span class="token punctuation">(</span><span class="token string">&quot;$TAG[]&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
      <span class="token keyword">var</span> className<span class="token operator">=</span><span class="token function">changeFirstChar</span><span class="token punctuation">(</span>v<span class="token punctuation">.</span><span class="token function">substring</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token keyword">if</span><span class="token punctuation">(</span>className<span class="token punctuation">.</span><span class="token function">toLowerCase</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">!=</span>current<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">set</span><span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token string">&apos;import &quot;$className.dart&quot;&apos;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span>
      <span class="token keyword">return</span> <span class="token string">&quot;List&lt;${changeFirstChar(className)}&gt;&quot;</span><span class="token punctuation">;</span>

    <span class="token punctuation">}</span><span class="token keyword">else</span> <span class="token keyword">if</span><span class="token punctuation">(</span>v<span class="token punctuation">.</span><span class="token function">startsWith</span><span class="token punctuation">(</span>TAG<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
      <span class="token keyword">var</span> fileName<span class="token operator">=</span><span class="token function">changeFirstChar</span><span class="token punctuation">(</span>v<span class="token punctuation">.</span><span class="token function">substring</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token keyword">if</span><span class="token punctuation">(</span>fileName<span class="token punctuation">.</span><span class="token function">toLowerCase</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">!=</span>current<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">set</span><span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token string">&apos;import &quot;$fileName.dart&quot;&apos;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span>
      <span class="token keyword">return</span> <span class="token function">changeFirstChar</span><span class="token punctuation">(</span>fileName<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">return</span> <span class="token string">&quot;String&quot;</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span><span class="token keyword">else</span><span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token string">&quot;String&quot;</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
 <span class="token punctuation">}</span>

<span class="token comment">//&#x66FF;&#x6362;&#x6A21;&#x677F;&#x5360;&#x4F4D;&#x7B26;</span>
String <span class="token function">format</span><span class="token punctuation">(</span>String fmt<span class="token punctuation">,</span> List<span class="token operator">&lt;</span>Object<span class="token operator">&gt;</span> params<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  int matchIndex <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
  String <span class="token function">replace</span><span class="token punctuation">(</span>Match m<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span>matchIndex <span class="token operator">&lt;</span> params<span class="token punctuation">.</span>length<span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">switch</span> <span class="token punctuation">(</span>m<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">case</span> <span class="token string">&quot;%s&quot;</span><span class="token punctuation">:</span>
          <span class="token keyword">return</span> params<span class="token punctuation">[</span>matchIndex<span class="token operator">++</span><span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
      <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">Exception</span><span class="token punctuation">(</span><span class="token string">&quot;Missing parameter for string format&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">Exception</span><span class="token punctuation">(</span><span class="token string">&quot;Invalid format string: &quot;</span> <span class="token operator">+</span> m<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
  <span class="token keyword">return</span> fmt<span class="token punctuation">.</span><span class="token function">replaceAllMapped</span><span class="token punctuation">(</span><span class="token string">&quot;%s&quot;</span><span class="token punctuation">,</span> replace<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
  <span class="token function">walk</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
</li>
<li><p>&#x5199;&#x4E00;&#x4E2A;shell(mo.sh)&#xFF0C;&#x5C06;&#x751F;&#x6210;&#x6A21;&#x677F;&#x548C;&#x751F;&#x6210;model&#x4E32;&#x8D77;&#x6765;&#xFF1A;</p>
<pre class="language-"><code class="lang-sh">dart mo.dart
flutter packages pub run build_runner build --delete-conflicting-outputs
</code></pre>
</li>
</ol>
<p>&#x81F3;&#x6B64;&#xFF0C;&#x6211;&#x4EEC;&#x7684;&#x811A;&#x672C;&#x5199;&#x597D;&#x4E86;&#xFF0C;&#x6211;&#x4EEC;&#x5728;&#x6839;&#x76EE;&#x5F55;&#x4E0B;&#x65B0;&#x5EFA;&#x4E00;&#x4E2A;json&#x76EE;&#x5F55;&#xFF0C;&#x7136;&#x540E;&#x628A;user.json&#x79FB;&#x8FDB;&#x53BB;&#xFF0C;&#x7136;&#x540E;&#x5728;lib&#x76EE;&#x5F55;&#x4E0B;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;models&#x76EE;&#x5F55;&#xFF0C;&#x7528;&#x4E8E;&#x4FDD;&#x5B58;&#x6700;&#x7EC8;&#x751F;&#x6210;&#x7684;Model&#x7C7B;&#x3002;&#x73B0;&#x5728;&#x6211;&#x4EEC;&#x53EA;&#x9700;&#x8981;&#x4E00;&#x53E5;&#x547D;&#x4EE4;&#x5373;&#x53EF;&#x751F;&#x6210;Model&#x7C7B;&#x4E86;:</p>
<pre class="language-"><code>./mo.sh
</code></pre><p>&#x8FD0;&#x884C;&#x540E;&#xFF0C;&#x4E00;&#x5207;&#x90FD;&#x5C06;&#x81EA;&#x52A8;&#x6267;&#x884C;&#xFF0C;&#x73B0;&#x5728;&#x597D;&#x591A;&#x4E86;&#xFF0C;&#x4E0D;&#x662F;&#x5417;&#xFF1F;</p>
<h4 id="&#x5D4C;&#x5957;json">&#x5D4C;&#x5957;JSON</h4>
<p>&#x6211;&#x4EEC;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;person.json&#x5185;&#x5BB9;&#x4FEE;&#x6539;&#x4E3A;&#xFF1A;</p>
<pre class="language-"><code class="lang-json"><span class="token punctuation">{</span>
  <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;John Smith&quot;</span><span class="token punctuation">,</span>
  <span class="token property">&quot;email&quot;</span><span class="token operator">:</span> <span class="token string">&quot;john@example.com&quot;</span><span class="token punctuation">,</span>
  <span class="token property">&quot;mother&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span>
    <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;Alice&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;email&quot;</span><span class="token operator">:</span><span class="token string">&quot;alice@example.com&quot;</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token property">&quot;friends&quot;</span><span class="token operator">:</span><span class="token punctuation">[</span>
    <span class="token punctuation">{</span>
      <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;Jack&quot;</span><span class="token punctuation">,</span>
      <span class="token property">&quot;email&quot;</span><span class="token operator">:</span><span class="token string">&quot;Jack@example.com&quot;</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token punctuation">{</span>
      <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;Nancy&quot;</span><span class="token punctuation">,</span>
      <span class="token property">&quot;email&quot;</span><span class="token operator">:</span><span class="token string">&quot;Nancy@example.com&quot;</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">]</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x6BCF;&#x4E2A;Person&#x90FD;&#x6709;<code>name</code> &#x3001;<code>email</code> &#x3001; <code>mother</code>&#x548C;<code>friends</code>&#x56DB;&#x4E2A;&#x5B57;&#x6BB5;&#xFF0C;&#x7531;&#x4E8E;<code>mother</code>&#x4E5F;&#x662F;&#x4E00;&#x4E2A;Person&#xFF0C;&#x670B;&#x53CB;&#x662F;&#x591A;&#x4E2A;Person(&#x6570;&#x7EC4;)&#xFF0C;&#x6240;&#x4EE5;&#x6211;&#x4EEC;&#x671F;&#x671B;&#x751F;&#x6210;&#x7684;Model&#x662F;&#x4E0B;&#x9762;&#x8FD9;&#x6837;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token keyword">import</span> <span class="token string">&apos;package:json_annotation/json_annotation.dart&apos;</span><span class="token punctuation">;</span>
<span class="token keyword">part</span> <span class="token string">&apos;person.g.dart&apos;</span><span class="token punctuation">;</span>

<span class="token metadata symbol">@JsonSerializable</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">class</span> <span class="token class-name">Person</span> <span class="token punctuation">{</span>
    <span class="token function">Person</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    String name<span class="token punctuation">;</span>
    String email<span class="token punctuation">;</span>
    Person mother<span class="token punctuation">;</span>
    List<span class="token operator">&lt;</span>Person<span class="token operator">&gt;</span> friends<span class="token punctuation">;</span>

    <span class="token keyword">factory</span> Person<span class="token punctuation">.</span><span class="token function">fromJson</span><span class="token punctuation">(</span>Map<span class="token operator">&lt;</span>String<span class="token punctuation">,</span><span class="token keyword">dynamic</span><span class="token operator">&gt;</span> json<span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span> _$<span class="token function">PersonFromJson</span><span class="token punctuation">(</span>json<span class="token punctuation">)</span><span class="token punctuation">;</span>
    Map<span class="token operator">&lt;</span>String<span class="token punctuation">,</span> <span class="token keyword">dynamic</span><span class="token operator">&gt;</span> <span class="token function">toJson</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span> _$<span class="token function">PersonToJson</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x8FD9;&#x65F6;&#xFF0C;&#x6211;&#x4EEC;&#x53EA;&#x9700;&#x8981;&#x7B80;&#x5355;&#x4FEE;&#x6539;&#x4E00;&#x4E0B;JSON&#xFF0C;&#x6DFB;&#x52A0;&#x4E00;&#x4E9B;&#x7279;&#x6B8A;&#x6807;&#x5FD7;&#xFF0C;&#x91CD;&#x65B0;&#x8FD0;&#x884C;mo.sh&#x5373;&#x53EF;&#xFF1A;</p>
<pre class="language-"><code class="lang-json"><span class="token punctuation">{</span>
  <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;John Smith&quot;</span><span class="token punctuation">,</span>
  <span class="token property">&quot;email&quot;</span><span class="token operator">:</span> <span class="token string">&quot;john@example.com&quot;</span><span class="token punctuation">,</span>
  <span class="token property">&quot;mother&quot;</span><span class="token operator">:</span><span class="token string">&quot;$person&quot;</span><span class="token punctuation">,</span>
  <span class="token property">&quot;friends&quot;</span><span class="token operator">:</span><span class="token string">&quot;$[]person&quot;</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x6211;&#x4EEC;&#x4F7F;&#x7528;&#x7F8E;&#x5143;&#x7B26;&#x201C;$&#x201D;&#x4F5C;&#x4E3A;&#x7279;&#x6B8A;&#x6807;&#x5FD7;&#x7B26;(&#x5982;&#x679C;&#x4E0E;&#x5185;&#x5BB9;&#x51B2;&#x7A81;&#xFF0C;&#x53EF;&#x4EE5;&#x4FEE;&#x6539;mo.dart&#x4E2D;&#x7684;<code>TAG</code>&#x5E38;&#x91CF;&#xFF0C;&#x81EA;&#x5B9A;&#x4E49;&#x6807;&#x5FD7;&#x7B26;)&#xFF0C;&#x811A;&#x672C;&#x5728;&#x9047;&#x5230;&#x7279;&#x6B8A;&#x6807;&#x5FD7;&#x7B26;&#x540E;&#x4F1A;&#x5148;&#x628A;&#x76F8;&#x5E94;&#x5B57;&#x6BB5;&#x8F6C;&#x4E3A;&#x76F8;&#x5E94;&#x7684;&#x5BF9;&#x8C61;&#x6216;&#x5BF9;&#x8C61;&#x6570;&#x7EC4;&#xFF0C;&#x5BF9;&#x8C61;&#x6570;&#x7EC4;&#x9700;&#x8981;&#x5728;&#x6807;&#x5FD7;&#x7B26;&#x540E;&#x9762;&#x6DFB;&#x52A0;&#x6570;&#x7EC4;&#x7B26;&#x201C;[]&#x201D;&#xFF0C;&#x7B26;&#x53F7;&#x540E;&#x9762;&#x63A5;&#x5177;&#x4F53;&#x7684;&#x7C7B;&#x578B;&#x540D;&#xFF0C;&#x6B64;&#x4F8B;&#x4E2D;&#x662F;person&#x3002;&#x5176;&#x5B83;&#x7C7B;&#x578B;&#x540C;&#x7406;&#xFF0C;&#x52A0;&#x5165;&#x6211;&#x4EEC;&#x7ED9;User&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;Person&#x7C7B;&#x578B;&#x7684; <code>boss</code>&#x5B57;&#x6BB5;&#xFF1A;</p>
<pre class="language-"><code class="lang-json"><span class="token punctuation">{</span>
  <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;John Smith&quot;</span><span class="token punctuation">,</span>
  <span class="token property">&quot;email&quot;</span><span class="token operator">:</span> <span class="token string">&quot;john@example.com&quot;</span><span class="token punctuation">,</span>
  <span class="token property">&quot;boss&quot;</span><span class="token operator">:</span><span class="token string">&quot;$person&quot;</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x91CD;&#x65B0;&#x8FD0;&#x884C;mo.sh&#xFF0C;&#x751F;&#x6210;&#x7684;user.dart&#x5982;&#x4E0B;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token keyword">import</span> <span class="token string">&apos;package:json_annotation/json_annotation.dart&apos;</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token string">&quot;person.dart&quot;</span><span class="token punctuation">;</span>
<span class="token keyword">part</span> <span class="token string">&apos;user.g.dart&apos;</span><span class="token punctuation">;</span>

<span class="token metadata symbol">@JsonSerializable</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

<span class="token keyword">class</span> <span class="token class-name">User</span> <span class="token punctuation">{</span>
    <span class="token function">User</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    String name<span class="token punctuation">;</span>
    String email<span class="token punctuation">;</span>
    Person boss<span class="token punctuation">;</span>

    <span class="token keyword">factory</span> User<span class="token punctuation">.</span><span class="token function">fromJson</span><span class="token punctuation">(</span>Map<span class="token operator">&lt;</span>String<span class="token punctuation">,</span><span class="token keyword">dynamic</span><span class="token operator">&gt;</span> json<span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span> _$<span class="token function">UserFromJson</span><span class="token punctuation">(</span>json<span class="token punctuation">)</span><span class="token punctuation">;</span>
    Map<span class="token operator">&lt;</span>String<span class="token punctuation">,</span> <span class="token keyword">dynamic</span><span class="token operator">&gt;</span> <span class="token function">toJson</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span> _$<span class="token function">UserToJson</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x53EF;&#x4EE5;&#x770B;&#x5230;&#xFF0C;<code>boss</code>&#x5B57;&#x6BB5;&#x5DF2;&#x81EA;&#x52A8;&#x6DFB;&#x52A0;&#xFF0C;&#x5E76;&#x81EA;&#x52A8;&#x5BFC;&#x5165;&#x4E86;&#x201C;person.dart&#x201D;&#x3002;</p>
<h3 id="jsonmodel-&#x5305;">Json_model &#x5305;</h3>
<p>&#x5982;&#x679C;&#x6BCF;&#x4E2A;&#x9879;&#x76EE;&#x90FD;&#x8981;&#x6784;&#x5EFA;&#x4E00;&#x4E2A;&#x4E0A;&#x9762;&#x8FD9;&#x6837;&#x7684;&#x811A;&#x672C;&#x663E;&#x7136;&#x5F88;&#x9EBB;&#x70E6;&#xFF0C;&#x4E3A;&#x6B64;&#xFF0C;&#x6211;&#x4EEC;&#x5C06;&#x4E0A;&#x9762;&#x811A;&#x672C;&#x548C;&#x751F;&#x6210;&#x6A21;&#x677F;&#x5C01;&#x88C5;&#x4E86;&#x4E00;&#x4E2A;&#x5305;,&#x5DF2;&#x7ECF;&#x53D1;&#x5E03;&#x5230;&#x4E86;Pub&#x4E0A;&#xFF0C;&#x5305;&#x540D;&#x4E3A;<a href="https://github.com/flutterchina/json_model" target="_blank">Json_model</a>&#xFF0C;&#x5F00;&#x53D1;&#x8005;&#x628A;&#x8BE5;&#x5305;&#x52A0;&#x5165;&#x5F00;&#x53D1;&#x4F9D;&#x8D56;&#x540E;&#xFF0C;&#x4FBF;&#x53EF;&#x4EE5;&#x7528;&#x4E00;&#x6761;&#x547D;&#x4EE4;&#xFF0C;&#x6839;&#x636E;Json&#x6587;&#x4EF6;&#x751F;&#x6210;Dart&#x7C7B;&#x3002;&#x53E6;&#x5916;<a href="https://github.com/flutterchina/json_model" target="_blank">Json_model</a> &#x5904;&#x4E8E;&#x8FED;&#x4EE3;&#x4E2D;&#xFF0C;&#x529F;&#x80FD;&#x4F1A;&#x9010;&#x6E10;&#x5B8C;&#x5584;&#xFF0C;&#x6240;&#x4EE5;&#x5EFA;&#x8BAE;&#x8BFB;&#x8005;&#x76F4;&#x63A5;&#x4F7F;&#x7528;&#x8BE5;&#x5305;&#xFF08;&#x800C;&#x4E0D;&#x662F;&#x624B;&#x52A8;&#x590D;&#x5236;&#x4E0A;&#x9762;&#x7684;&#x4EE3;&#x7801;&#xFF09;&#x3002;</p>
<h3 id="&#x4F7F;&#x7528;ide&#x63D2;&#x4EF6;&#x751F;&#x6210;model">&#x4F7F;&#x7528;IDE&#x63D2;&#x4EF6;&#x751F;&#x6210;model</h3>
<p>&#x76EE;&#x524D;Android Studio(&#x6216;IntelliJ)&#x6709;&#x51E0;&#x4E2A;&#x63D2;&#x4EF6;&#xFF0C;&#x53EF;&#x4EE5;&#x5C06;json&#x6587;&#x4EF6;&#x8F6C;&#x6210;Model&#x7C7B;&#xFF0C;&#x4F46;&#x63D2;&#x4EF6;&#x8D28;&#x91CF;&#x53C2;&#x5DEE;&#x4E0D;&#x9F50;&#xFF0C;&#x751A;&#x81F3;&#x8FD8;&#x6709;&#x4E00;&#x4E9B;&#x6CBE;&#x67D3;&#x4E0A;&#x4E86;&#x6284;&#x88AD;&#x98CE;&#x6CE2;&#xFF0C;&#x6545;&#x7B14;&#x8005;&#x5728;&#x6B64;&#x4E0D;&#x505A;&#x4F18;&#x5148;&#x63A8;&#x8350;&#xFF0C;&#x8BFB;&#x8005;&#x6709;&#x5174;&#x8DA3;&#x53EF;&#x4EE5;&#x81EA;&#x884C;&#x4E86;&#x89E3;&#x3002;&#x4F46;&#x662F;&#xFF0C;&#x6211;&#x4EEC;&#x8FD8;&#x662F;&#x8981;&#x4E86;&#x89E3;&#x4E00;&#x4E0B;IDE&#x63D2;&#x4EF6;&#x548C;<a href="https://link.juejin.im?target=https%3A%2F%2Fgithub.com%2Fflutterchina%2Fjson_model" target="_blank">Json_model</a>&#x7684;&#x4F18;&#x52A3;&#xFF1A;</p>
<ol>
<li><a href="https://link.juejin.im?target=https%3A%2F%2Fgithub.com%2Fflutterchina%2Fjson_model" target="_blank">Json_model</a>&#x9700;&#x8981;&#x5355;&#x72EC;&#x7EF4;&#x62A4;&#x4E00;&#x4E2A;&#x5B58;&#x653E;Json&#x6587;&#x4EF6;&#x7684;&#x6587;&#x4EF6;&#x5939;&#xFF0C;&#x5982;&#x679C;&#x6709;&#x6539;&#x52A8;&#xFF0C;&#x53EA;&#x9700;&#x4FEE;&#x6539;Json&#x6587;&#x4EF6;&#x4FBF;&#x53EF;&#x91CD;&#x65B0;&#x751F;&#x6210;Model&#x7C7B;&#xFF1B;&#x800C;IDE&#x63D2;&#x4EF6;&#x4E00;&#x822C;&#x9700;&#x8981;&#x7528;&#x6237;&#x624B;&#x52A8;&#x5C06;Json&#x5185;&#x5BB9;&#x62F7;&#x8D1D;&#x590D;&#x5236;&#x5230;&#x4E00;&#x4E2A;&#x8F93;&#x5165;&#x6846;&#x4E2D;&#xFF0C;&#x8FD9;&#x6837;&#x751F;&#x6210;&#x4E4B;&#x540E;Json&#x6587;&#x4EF6;&#x6CA1;&#x6709;&#x5B58;&#x6863;&#x7684;&#x5316;&#xFF0C;&#x4E4B;&#x540E;&#x8981;&#x6539;&#x52A8;&#x5C31;&#x9700;&#x8981;&#x624B;&#x52A8;&#x3002;</li>
<li><a href="https://link.juejin.im?target=https%3A%2F%2Fgithub.com%2Fflutterchina%2Fjson_model" target="_blank">Json_model</a>&#x53EF;&#x4EE5;&#x624B;&#x52A8;&#x6307;&#x5B9A;&#x67D0;&#x4E2A;&#x5B57;&#x6BB5;&#x5F15;&#x7528;&#x7684;&#x5176;&#x5B83;Model&#x7C7B;&#xFF0C;&#x53EF;&#x4EE5;&#x907F;&#x514D;&#x751F;&#x6210;&#x91CD;&#x590D;&#x7684;&#x7C7B;&#xFF1B;&#x800C;IDE&#x63D2;&#x4EF6;&#x4E00;&#x822C;&#x4F1A;&#x4E3A;&#x6BCF;&#x4E00;&#x4E2A;Json&#x6587;&#x4EF6;&#x4E2D;&#x6240;&#x6709;&#x5D4C;&#x5957;&#x5BF9;&#x8C61;&#x90FD;&#x5355;&#x72EC;&#x751F;&#x6210;&#x4E00;&#x4E2A;Model&#x7C7B;&#xFF0C;&#x5373;&#x4F7F;&#x8FD9;&#x4E9B;&#x5D4C;&#x5957;&#x5BF9;&#x8C61;&#x53EF;&#x80FD;&#x5728;&#x5176;&#x5B83;Model&#x7C7B;&#x4E2D;&#x5DF2;&#x7ECF;&#x751F;&#x6210;&#x8FC7;&#x3002;</li>
<li><a href="https://link.juejin.im?target=https%3A%2F%2Fgithub.com%2Fflutterchina%2Fjson_model" target="_blank">Json_model</a> &#x63D0;&#x4F9B;&#x4E86;&#x547D;&#x4EE4;&#x884C;&#x8F6C;&#x5316;&#x65B9;&#x5F0F;&#xFF0C;&#x53EF;&#x4EE5;&#x65B9;&#x4FBF;&#x96C6;&#x6210;&#x5230;CI&#x7B49;&#x975E;UI&#x73AF;&#x5883;&#x7684;&#x573A;&#x666F;&#x3002;</li>
</ol>
<h3 id="faq">FAQ</h3>
<p>&#x5F88;&#x591A;&#x4EBA;&#x53EF;&#x80FD;&#x4F1A;&#x95EE;Flutter&#x4E2D;&#x6709;&#x6CA1;&#x6709;&#x50CF;Java&#x5F00;&#x53D1;&#x4E2D;&#x7684;Gson/Jackson&#x4E00;&#x6837;&#x7684;Json&#x5E8F;&#x5217;&#x5316;&#x7C7B;&#x5E93;&#xFF1F;&#x7B54;&#x6848;&#x662F;&#x6CA1;&#x6709;&#xFF01;&#x56E0;&#x4E3A;&#x8FD9;&#x6837;&#x7684;&#x5E93;&#x9700;&#x8981;&#x4F7F;&#x7528;&#x8FD0;&#x884C;&#x65F6;&#x53CD;&#x5C04;&#xFF0C;&#x8FD9;&#x5728;Flutter&#x4E2D;&#x662F;&#x7981;&#x7528;&#x7684;&#x3002;&#x8FD0;&#x884C;&#x65F6;&#x53CD;&#x5C04;&#x4F1A;&#x5E72;&#x6270;Dart&#x7684;<em>tree shaking</em>&#xFF0C;&#x4F7F;&#x7528;<em>tree shaking</em>&#xFF0C;&#x53EF;&#x4EE5;&#x5728;release&#x7248;&#x4E2D;&#x201C;&#x53BB;&#x9664;&#x201D;&#x672A;&#x4F7F;&#x7528;&#x7684;&#x4EE3;&#x7801;&#xFF0C;&#x8FD9;&#x53EF;&#x4EE5;&#x663E;&#x8457;&#x4F18;&#x5316;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x7684;&#x5927;&#x5C0F;&#x3002;&#x7531;&#x4E8E;&#x53CD;&#x5C04;&#x4F1A;&#x9ED8;&#x8BA4;&#x5E94;&#x7528;&#x5230;&#x6240;&#x6709;&#x4EE3;&#x7801;&#xFF0C;&#x56E0;&#x6B64;<em>tree shaking</em>&#x4F1A;&#x5F88;&#x96BE;&#x5DE5;&#x4F5C;&#xFF0C;&#x56E0;&#x4E3A;&#x5728;&#x542F;&#x7528;&#x53CD;&#x5C04;&#x65F6;&#x5F88;&#x96BE;&#x77E5;&#x9053;&#x54EA;&#x4E9B;&#x4EE3;&#x7801;&#x672A;&#x88AB;&#x4F7F;&#x7528;&#xFF0C;&#x56E0;&#x6B64;&#x5197;&#x4F59;&#x4EE3;&#x7801;&#x5F88;&#x96BE;&#x5265;&#x79BB;&#xFF0C;&#x6240;&#x4EE5;Flutter&#x4E2D;&#x7981;&#x7528;&#x4E86;Dart&#x7684;&#x53CD;&#x5C04;&#x529F;&#x80FD;&#xFF0C;&#x800C;&#x6B63;&#x56E0;&#x5982;&#x6B64;&#x4E5F;&#x5C31;&#x65E0;&#x6CD5;&#x5B9E;&#x73B0;&#x52A8;&#x6001;&#x8F6C;&#x5316;Model&#x7684;&#x529F;&#x80FD;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="socket.html" class="navigation navigation-prev " aria-label="Previous page: 11.6：使用Socket API">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="../chapter12/" class="navigation navigation-next " aria-label="Next page: 第十二章：包与插件">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"11.7：Json转Dart Model类","level":"3.4.7","depth":2,"next":{"title":"第十二章：包与插件","level":"3.5","depth":1,"path":"chapter12/index.md","ref":"chapter12/index.md","articles":[{"title":"12.1：开发package","level":"3.5.1","depth":2,"path":"chapter12/develop_package.md","ref":"chapter12/develop_package.md","articles":[]},{"title":"12.2：平台通道简介","level":"3.5.2","depth":2,"path":"chapter12/platform-channel.md","ref":"chapter12/platform-channel.md","articles":[]},{"title":"12.3：开发Flutter插件","level":"3.5.3","depth":2,"path":"chapter12/develop_plugin.md","ref":"chapter12/develop_plugin.md","articles":[]},{"title":"12.4：插件开发：实现Android端API","level":"3.5.4","depth":2,"path":"chapter12/android_implement.md","ref":"chapter12/android_implement.md","articles":[]},{"title":"12.5：插件开发：实现IOS端API","level":"3.5.5","depth":2,"path":"chapter12/ios_implement.md","ref":"chapter12/ios_implement.md","articles":[]},{"title":"12.6：Texture和PlatformView","level":"3.5.6","depth":2,"path":"chapter12/texture_platformview.md","ref":"chapter12/texture_platformview.md","articles":[]}]},"previous":{"title":"11.6：使用Socket API","level":"3.4.6","depth":2,"path":"chapter11/socket.md","ref":"chapter11/socket.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-search","search-pro","ace","splitter","prism","donate","-highlight"],"root":"docs","styles":{"website":"styles/website.css","ebook":"styles/ebook.css","pdf":"styles/pdf.css","mobi":"styles/mobi.css","epub":"styles/epub.css"},"pluginsConfig":{"prism":{"lang":{"shell":"bash"}},"ace":{},"splitter":{},"search-pro":{"cutWordLib":"nodejieba","defineWord":["Gitbook Use"]},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"donate":{"alipay":"","alipayText":"支付宝打赏","button":"赏","title":"","wechat":"https://pcdn.flutterchina.club/imgs/pay.jpeg","wechatText":"微信打赏"},"fontsettings":{"theme":"white","family":"sans","size":2},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"wendux 824783146@qq.com","bookRoot":"https://book.flutterchina.club/","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"《Flutter实战》","language":"zh-hans","links":{"sharing":{"all":null,"facebook":null,"google":null,"twitter":null,"weibo":null},"sidebar":{"<div><img height=20 style='position:relative; top:5px; padding-right:5px ' src='https://cdn.jsdelivr.net/gh/flutterchina/website@1.0/images/favicon.png'/> Flutter中文网</div>":"https://flutterchina.club"}},"gitbook":"*","description":"记录Gitbook的配置和一些插件的使用"},"file":{"path":"chapter11/json_model.md","mtime":"2019-08-06T11:10:58.909Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-05-05T06:01:05.405Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>



    <script src="https://pcdn.flutterchina.club/gitbook/gitbook.js"></script>
    <script src="https://pcdn.flutterchina.club/gitbook/theme.js"></script>
    
        
        <script src="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-ace/ace/ace.js"></script>
        
    
        
        <script src="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-ace/ace.js"></script>
        
    
        
        <script src="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-donate/plugin.js"></script>
        
    
        
        <script src="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    


<script src="https://pcdn.flutterchina.club/gitbook/pub.js"></script>
</body>

</html>

